<!DOCTYPE html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加字典内容信息</title>
    <link rel="stylesheet" href="../css/from.css">
    <link rel="stylesheet" href="../themes/default/easyui.css">
    <link rel="stylesheet" href="../themes/icon.css">
    <script src="../js/jquery.min.js"></script>
    <script src="../js/jquery.easyui.min.js"></script>
    <script src="../js/easyui-lang-zh_CN.js"></script>
    <script>
       $(function(){
	    $("#save").click(function(){
		    var dictType=$("#dictType").val();
		    var value=$("#value").textbox("getValue");
		    var key=$("#key").textbox("getValue");
		    if(key==null||key==''){
		        alert("请输入字典名称!");
		        return;
		    }else{
		       $.ajax({
				      type:"post",//请求类型
				      url:"/kxmanage/dictDetail/checkDictKey", 
				      data:{"key":key},
				      dataType:"json",//ajax接口（请求url）返回的数据类型
				      success:function(data){//data：返回数据（json对象）
				         if(data.result=="bucunzai"){
							var sortNumber=$("#sortNumber").textbox("getValue");
				       		var reg = new RegExp("^[0-9]+$");  
						    if(!reg.test(sortNumber)){  
						        alert("请输入数字!");
						        return;
						    }  
						    var memo=$("#memo").textbox("getValue");
						    var show=$("[name='show']:checked").val();
						    value=parseInt(value,10);		    
						    sortNumber=parseInt(sortNumber,10);		    
						    
						    if(dictType==null || dictType==''){
							   $.messager.alert('我的消息','请填写所属类别!','warning');
						    }else{
							       $.ajax({
								      type:"post",//请求类型
								      url:"/kxmanage/dictDetail/addDict", 
								      data:{"type":dictType,"value":value,"key":key,"sortNumber":sortNumber,"memo":memo,"show":show},
								      dataType:"json",//ajax接口（请求url）返回的数据类型
								      success:function(data){//data：返回数据（json对象）
								         if(data.result=="error"){
								          alert("添加失败");
								         }
								         else if(data.result=="success"){
								          alert("添加成功");
						                  parent.addTabs('字典内容管理','goods/dictManagement.jsp');
								          parent.closeTabs('字典内容信息');
								         }
								      }  
							       }); 
							}
				         }else{
				            alert("字典名称重复!");
				         }
				      }
			   }); 	
			 }        
	    });
	    
	      $.ajax({
         	type:"GET",//请求类型
		 	url:"/kxmanage/dictDetail/findalltype",//请求的url
		 	dataType:"json",//ajax接口（请求url）返回的数据类型
		 	success:function(data){//data：返回数据（json对象）
		 		if(data != null){
		 			$("#dictType").html("");
					var options = "<option value=\"\">——请选择——</option>";
					for(var i = 0; i < data.length; i++){
						options += "<option value=\""+data[i].type+"\">"+data[i].type+"</option>";
					}
					$("#dictType").html(options);
					}
		 	}
          });
	    
	     $("#dictType").change(function(){
	       var dictType=$(this).val();
	       if(dictType==""||dictType==null){
	           $("#value").textbox('setValue',"");
               $("#sortNumber").textbox('setValue',"");
               return ; 
	       }
	        $.ajax({
         	type:"post",//请求类型
		 	url:"/kxmanage/dictDetail/getDictByType",//请求的url
		 	data:{"dictType":dictType},
		 	dataType:"json",//ajax接口（请求url）返回的数据类型
		 	success:function(data){//data：返回数据（json对象）
               $("#value").textbox('setValue',data);
               $("#sortNumber").textbox('setValue',data);
 		    }
            });
         }); 
         
       });
       
         function reload(){
            window.location.reload();
         }  
         
         function Close(){
            parent.closeTabs("字典内容信息");
         }
         
                  
    </script>
    <style>
        body {
            font-size:12px;
            padding:10px
        }
        .l-table-edit {
          border-collapse:collapse;
          border-spacing:0;
        }
        .l-table-edit-td {
            padding:4px;
            font-size:12px;
            border:1px solid #84a0c4 
        }
        
    </style>


</head>
<body>
<form name="form"  id="form" action="" method="post">
    <table cellpadding="0" cellspacing="0" class="l-table-edit" style="width:100%">
        <tr >
            <td width="17%"  align="right" class="l-table-edit-td">所属类别：</td>
            <td width="27%" align="left" class="l-table-edit-td">
                 <select name="type" id="dictType" style="width:120px;height:20px" panelHeight="120px">
                 </select>  
            </td>
            <td width="13%"  align="right" class="l-table-edit-td">字典编号：</td>
            <td width="43%" align="left" class="l-table-edit-td"><input  type="text" id="value" readonly="readonly" name="value" value="" maxlength="30" class="easyui-textbox" style="height:20px"/></td>
        </tr>
        <tr>
            <td width="17%" align="right" class="l-table-edit-td">字典名称：</td>
            <td width="27%" align="left" class="l-table-edit-td"><input  type="text" id="key" name="key" class="easyui-textbox" value=""  maxlength="50" ltype="text" style="height:20px"/></td>
            <td width="13%" align="right" class="l-table-edit-td">排序编号：</td>
            <td width="43%" align="left" class="l-table-edit-td"><input type="text" id="sortNumber" name="sortNumber" class="easyui-textbox" value="" maxlength="50"  ltype="text" style="height:20px"/><br/>(请按001格式填写，001为最先)</td>
        </tr>
        <tr>
            <td width="17%" align="right" class="l-table-edit-td">显示状态：</td>
            <td width="27%" align="left" class="l-table-edit-td">
             <input type="radio" name="show" checked value="1"/>显示<input type="radio" name="show" value="2"/>隐藏
            </td>
            <td width="13%" align="right" class="l-table-edit-td">备注：</td>
            <td width="43%"align="left" class="l-table-edit-td"><input type="text"  class="easyui-textbox"  id="memo" name="memo" value="" maxlength="50"  ltype="text" style="height:20px"/></td>
        </tr>
    </table>
</form>
<br>
<input type="hidden" id="path" value="${pageContext.request.contextPath}"/>
<input  type="button" value="新   增" onclick="reload()" style="width:60px">
<a href="javascript:;"><input id="save" type="button" value="保存" style="width:60px"></a>
<input  type="button" value="打印" style="width:60px">
<input  type="button" onclick="Close()" value="关闭" style="width:60px">
</body>
</html>